package easy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution_1200 {

    public List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        int min = Integer.MAX_VALUE;
        int[] ints = new int[arr.length - 1];
        for (int i = 0; i < ints.length; i++) {
            ints[i] = arr[i + 1] - arr[i];
            if (ints[i] < min) {
                min = ints[i];
            }
        }
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < ints.length; i++) {
            if (ints[i] == min) {
                List<Integer> temp = new ArrayList<>();
                temp.add(arr[i]);
                temp.add(arr[i + 1]);
                list.add(temp);
            }
        }
        return list;
    }

    /*public List<List<Integer>> minimumAbsDifference(int[] arr) {
        boolean[] flags = new boolean[2000001];
        for (int num : arr) {
            flags[num + 1000000] = true;
        }
        List<List<Integer>> list = new ArrayList<>();
        int preIndex = -1, min = Integer.MAX_VALUE;
        for (int i = 0; i < flags.length; i++) {
            if (flags[i]) {
                if (preIndex == -1) {
                    preIndex = i;
                } else {
                    int sub = i - preIndex;
                    if (sub > min) {
                        preIndex = i;
                        continue;
                    } else if (sub < min) {
                        min = sub;
                        list.clear();
                    }
                    List<Integer> temp = new ArrayList<>();
                    temp.add(preIndex);
                    temp.add(i);
                    list.add(temp);
                    preIndex = i;
                }
            }
        }
        for (List<Integer> integers : list) {
            integers.set(0, integers.get(0) - 1000000);
            integers.set(1, integers.get(1) - 1000000);
        }
        return list;
    }*/

    public static void main(String[] args) {
        Solution_1200 model = new Solution_1200();
        System.out.println(model.minimumAbsDifference(new int[]{4, 2, 1, 3}));
        System.out.println(model.minimumAbsDifference(new int[]{1, 3, 6, 10, 15}));
        System.out.println(model.minimumAbsDifference(new int[]{3, 8, -10, 23, 19, -4, -14, 27}));
    }
}
